/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */
package seedpod.webapp.view.htmlwidget;

public class TextInput extends GenericHtmlWidget {
	public static int MAX_LENGTH = 50;
	public static int DEFAULT_LENGTH = 10;

	private String _value = "";
	private int _maxLength = 50;
	private int _size = 10;
	protected String _type = "text";
	protected boolean _disabled = false;
	protected boolean _readonly = false;

	// Form containerForm;

	public TextInput(String widgetID) {
		super( widgetID );
	}

	public TextInput(String widgetID, String value) {
		super( widgetID );
		_value = value;
	}
	
	public void setValue(String value) {
		_value = value;
	}

	public void setSize( int size ) {
		_size = size;
	}
	
	

	public void setMaxLength( int max ) {
		_maxLength = max;
	}

	public void setType( String type ) {
		_type = type;
	}

	public String render() {
		String html = "<input ";
		html += ATT( "id", _widgetID );
		html += ATT( "name", _widgetID );
		html += ATT( "type", _type );
		html += ATT( "maxLength", _maxLength );
		html += ATT( "size", _size );
		html += ATT( "value", _value );
		html += ATT( "class", _cssClass );
		html += (_disabled) ? " disabled " : "";
		html += (_readonly) ? " readonly " : "";

		/**
		 * @todo need javascript extension capability
		 */
		html += "onKeyPress=\"sizeit(this);\" ";

		html += ">";
		return html;
	}

	public void disableInput( boolean disable ) {
		_disabled = disable;
	}
	
	public void readOnlyInput(boolean readonly) {
		_readonly = readonly;
	}
}